package ua.kpi.ustymenko.io;
import ua.kpi.ustymenko.testcase.Answers;
import ua.kpi.ustymenko.testcase.question.Question;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class TesterIO {
    private PrintStream printStream;
    private Scanner scanner;

    public TesterIO(InputStream in, OutputStream out) {
        scanner = new Scanner(in);
        printStream = new PrintStream(out);
    }

    public void outQuestion(Question question) {
        printStream.print(question);
    }

    public void outResult(double score) {
        printStream.format("Your score: %.2f points\n\n", score);
    }

    /**
     * Getting list of answers from user
     *
     * @param question question to get answer on
     * @return list of user answers
     */
    public Answers getUserAnswers(Question question) {
        printStream.print("Answer: ");
        String stringAnswer = scanner.nextLine();

        return question.getAnswersFromString(stringAnswer);
    }
}
